import 'package:flutter/material.dart';
import 'package:flutter_base/generated/assets.dart';

import 'image_view.dart';

/// 圆形头像
class CircleAvatarWidget extends StatelessWidget {
  final double radius;
  final Widget? placeholder;
  final String? imageUrl;
  final Color? backgroundColor;
  final Color? borderColor;
  final double? borderWidth;
  final int? sex;
  final double? sexWidth;
  final double? sexHeight;
  final String? avatarFrame;
  final String? avatarFrameSVGA;
  final double? avatarFrameSVGARate;

  const CircleAvatarWidget({
    required this.radius,
    this.backgroundColor = Colors.transparent,
    this.placeholder,
    this.borderColor = Colors.transparent,
    this.borderWidth = 0,
    this.imageUrl,
    this.sex,
    Key? key,
    this.sexWidth,
    this.sexHeight,
    this.avatarFrame,
    this.avatarFrameSVGA,
    this.avatarFrameSVGARate,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: radius * 2 + borderWidth! * 2,
      height: radius * 2 + borderWidth! * 2,
      decoration: (borderWidth == null || borderWidth == null)
          ? null
          : BoxDecoration(
              shape: BoxShape.circle,
              border: Border.all(color: borderColor!, width: borderWidth!),
            ),
      child: Stack(
        children: [
          AspectRatio(
            aspectRatio: 1.0,
            child: ImageView(
              imageUrl: imageUrl,
              placeholder: placeholder ??
                  ClipRRect(
                    borderRadius: BorderRadius.circular(radius),
                    child: Image.asset(Assets.avatarDefault),
                  ),
              radius: radius,
              maxBytes: (radius.toInt() * 2) << 10,
            ),
          ),
        ],
      ),
    );
  }
}
